<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='ttbl' /></title>

    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        html {background:#fff;}
    </style>

</head>

<body style="background:white;">
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">

    <form:form commandName="user" method="${_method }" class="layui-form">
        <input type="hidden" name="_method" value="${_method }"/>

        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='ymm' /></label>
            <div class="layui-input-inline">
                <input type="password" id="oldPassword" class="layui-input"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='xddrmm' /></label>
            <div class="layui-input-inline">
                <input type="password" id="newPassword" class="layui-input"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><fmt:message key='qrxddrmm' /></label>
            <div class="layui-input-inline">
                <input type="password" id="confirmNewPassword" class="layui-input"/>
            </div>
        </div>


        <div class="layui-input-block">
            <input type="button" value="<fmt:message key='xgmm' />" class="layui-btn layui-btn-normal" id="submit">
        </div>

    </form:form>
</div>

<script>
    $(function () {
        $("#submit").click(function () {

            if($("#oldPassword").val() == "" || $("#newPassword").val() == "" || $("#confirmNewPassword").val() == "") {
                layer.msg("<fmt:message key='mmbyxwk' />");
                return false;
            }

            if ($("#newPassword").val() !== $("#confirmNewPassword").val()) {
                layer.msg("<fmt:message key='lcsrdxmmbyz' />");
                return false;
            }

            if ($("#oldPassword").val() == $("#newPassword").val()) {
                layer.msg("<fmt:message key='qrsbyydxmm' />");
                return false;
            }

            $.ajax({
                url: "${web_domain}/securitys/users/modifyPassword",
                type: "post",
                dataType: "json",
                data: {
                    "_method": "put",
                    "oldPassword": $("#oldPassword").val(),
                    "newPassword": $("#newPassword").val()
                },
                success: function (result) {
                    if (result.status) {
                        layer.confirm("<fmt:message key='mmxgcgqcxdr' />", function () {
                            location.reload();
                        });
                    } else {
                        alert(result.message);
                    }

                }

            });

        });
    });
</script>
</body>
</fmt:bundle>
</html>